//
//  UserViewController.m
//  TrueLove
//
//  Created by han on 15-1-28.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "UserViewController.h"
#import "UserDetailViewController.h"
#import "CollectViewController.h"
#import "AboutViewController.h"
#import "DengluViewController.h"
@interface UserViewController () <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSMutableArray *arr1;
@property (nonatomic, retain) NSMutableArray *arr2;
@property (nonatomic, retain) NSMutableArray *arr3;
@property (nonatomic, retain) NSMutableArray *arr4;

@end

@implementation UserViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
     self.navigationController.navigationBar.translucent = NO;
    self.view.backgroundColor = [UIColor colorWithRed:244/255 green:244/255 blue:242/255 alpha:0.1];
    self.arr1 = [NSMutableArray arrayWithObjects:@"我的信息", @"我的收藏",nil];
    self.arr2 = [NSMutableArray arrayWithObjects:@"版本更新", @"关于我们", nil];
    self.arr3 = [NSMutableArray arrayWithObjects:@"清除缓存", @"退出登录", nil];
    self.arr4 = [NSMutableArray arrayWithObjects:@"夜间模式", nil];
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    [self setBackgroundImage];
    [self.tableView release];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return self.arr1.count;
    } else if(section == 1){
        return self.arr2.count;
    } else if (section == 2){
        return self.arr3.count;
    } else if(section == 3){
        return self.arr4.count;
    }
    return 10;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *str = @"str";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:str];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str] autorelease];
    }
    if (indexPath.section == 0) {
        cell.imageView.image = [UIImage imageNamed:@"iconfont-user"];
        cell.textLabel.text = [self.arr1 objectAtIndex:indexPath.row];
    } else if (indexPath.section == 1){
        cell.imageView.image = [UIImage imageNamed:@"iconfont-user"];

        cell.textLabel.text = [self.arr2 objectAtIndex:indexPath.row];
    } else if (indexPath.section == 2){
        cell.imageView.image = [UIImage imageNamed:@"iconfont-user"];

        cell.textLabel.text = [self.arr3 objectAtIndex:indexPath.row];
    } else {
        cell.imageView.image = [UIImage imageNamed:@"iconfont-user"];

        cell.textLabel.text = [self.arr4 objectAtIndex:indexPath.row];
    }
    
   
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
        return 45;
}
//分区尾
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 5.f;
}
//分区头
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 20.f;
}
//上方背景图片
- (void)setBackgroundImage
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.bounds.size.width, 140)];
    
    UIImageView *backImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.bounds.size.width, 140)];
    backImage.image = [UIImage imageNamed:@"m_6_634515417530312500_11187211.jpg"];
    [view addSubview:backImage];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    [button setBackgroundImage:[UIImage imageNamed:@"iconfont-user.png"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(140, 40, 100, 100);
    
    [view addSubview:button];
    
    self.tableView.tableHeaderView = view;
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            UserDetailViewController *userDetailVC = [[UserDetailViewController alloc] init];
            [self.navigationController pushViewController:userDetailVC animated:YES];
            [userDetailVC release];
            
        } else if (indexPath.row == 1){
            CollectViewController *collectVC = [[CollectViewController alloc] init];
            [self.navigationController pushViewController:collectVC animated:YES];
            [collectVC release];
            
        }
    } else if (indexPath.section == 1){
        if (indexPath.row == 1){
            AboutViewController *aboutVC = [[AboutViewController alloc] init];
            [self.navigationController pushViewController:aboutVC animated:YES];
            [aboutVC release];
        } else if (indexPath.row == 0){
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"更新失败" message:@"已是最新版本" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
            [alertView show];
            [alertView release];
        }

    }
}
- (void)button:(UIButton *)button
{
    DengluViewController *dengVC = [[DengluViewController alloc] init];
    [self.navigationController pushViewController:dengVC animated:YES];
    [dengVC release];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
